package net.pacman.model;

import android.graphics.Canvas;
import android.view.SurfaceView;
import java.util.ArrayList;
import java.util.Iterator;
import net.pacman.view.CharacterView;
import net.pacman.view.Renderer;

public class Labyrinth implements Renderer {

    private ArrayList<CharacterBase> listOfItens;
    private ArrayList<Character> listOfCharacters;
    private ArrayList<Renderer> listOfImages;
    private Pacman pacman;
    private SmartGhost cyan;
    private DumbGhost yellow;
    private Ghost pink;
    private Ghost red;
    private boolean touched;

    public Labyrinth(SurfaceView view) {

        pacman = new Pacman(10.0f, 10.0f);
        cyan = new SmartGhost(30.0f, 10.0f);
        yellow = new DumbGhost(60.0f, 10.0f);
        pink = new Ghost(90.0f, 10.0f);
        red = new Ghost(90.0f, 10.0f);

        listOfImages = new ArrayList<Renderer>();
        listOfImages.add(new CharacterView(view, pacman));
        listOfImages.add(new CharacterView(view, cyan));
        listOfImages.add(new CharacterView(view, yellow));
        listOfImages.add(new CharacterView(view, pink, true));
        listOfImages.add(new CharacterView(view, red, false));

        listOfCharacters = new ArrayList<Character>();
        listOfCharacters.add(pacman);
        listOfCharacters.add(cyan);
        listOfCharacters.add(pink);
        listOfCharacters.add(red);
        listOfCharacters.add(yellow);
    }

    public Pacman getPacman() {
        return pacman;
    }

    public void setTouched(boolean touched) {
        this.touched = touched;
    }

    public void draw(Canvas canvas) {

        if (pacman.isExist()) {
            Iterator<Renderer> it = listOfImages.iterator();
            while (it.hasNext()) {
                Renderer view = it.next();
                view.draw(canvas);
            }
        }
        else{
            
        }
    }

    public void update() {
        Iterator<Character> it = listOfCharacters.iterator();
        while (it.hasNext()) {
            Character character = it.next();
            character.update();
        }
    }
}
